<?php
namespace App\Models;
use Illuminate\Http\Request;
use DB;



/**
 * 管理员模型类
 */
class Project_admin_role_node extends BaseModel
{

    public $table = "project_admin_role_node";    //指定表名

    /**
     * 获取角色对应的节点
     * @param $rid
     * @return mixed
     */
    public static  function rGetNid($rid)
    {
        $rNid = DB::table('project_admin_role_node')->where('rid',$rid)->lists('nid');
        return  $rNid;
    }

    public static function saveRidNid($request)
    {

        DB::table('project_admin_role_node')->where('rid',$request->rId)->delete();  //清除数据

       $rNid = $request ->rNid;

       if(empty($rNid)){ return  false; }

       $node = [];   //处理添加数据
        foreach ($rNid as $k => $v) {
            $node[] = ['rid'=>$request->rId,'nid'=>$v];
       }
       return   DB::table('project_admin_role_node')->insert($node);
    }
}